<template>
	<view>
		<uni-nav-bar dark :fixed="true" shadow background-color="rgb(255, 0, 0)" status-bar left-icon="left"
			left-text="返回" :title="navbarTitle" @clickLeft="back" />
		<view class="pdf-list-page">
			<view class="pdf-grid">
				<view class="pdf-card" v-for="(pdf, index) in pdfFiles" :key="index" @click="openPdf(pdf)">
					<view class="pdf-icon" mode="aspectFit"></view>
					<view class="pdf-name">{{ pdf.name }}</view>
					<view class="empty" v-if="!pdfFiles || pdfFiles.length == 0">
						<text class="empty-text">没有任何文件</text>
					</view>
				</view>
			</view>
			<view class="bottom_tool">
				<view class="tool_box">
					<button type="warn" size="mini" v-if="isList==1" @click="conferenceList">会议列表</button>
					<button type="warn" size="mini" @click="back">返回上级</button>
					<!-- <button type="warn" size="mini" @click="jumpPage">文件首页</button> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	export default {
		data() {
			return {
				navbarTitle: '',
				// 假设文件都在 /ycmlMeeting 文件夹中
				pdfFiles: [],
				filekey: '',
				meetId: '',
				grouping: '',
				isList: null,
				sdRootPath: '/storage/emulated/0'
			}
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			conferenceList() {
				uni.redirectTo({
					url: '/pages/index/main',
					animationType: 'none',
					animationDuration: 0
				})
			},
			jumpPage() {
				this.pages.current = 1
				this.$refs.pdfview.jumpTo({
					// 页码
					page: Number(this.pages.current),
					// 是否开启动画
					animation: false
				});
			},
			openPdf(pdf) {
				if (!this.navbarTitle) return
				if (!pdf.filename) return
				if (this.grouping == "3") {
					if (pdf.classified == '1') {
						uni.showToast({
							title: '涉密文件，无权限查看！',
							icon: 'none',
							duration: 2000
						})
					} else {
						this.viewPdf(pdf);
					}
				} else {
					this.viewPdf(pdf);
				}
			},

			viewPdf(pdf) {
				const fisdRootPath =
					`${this.sdRootPath}/wzhxt_public/unzipped/ycmlMeeting/${this.meetId}/${this.navbarTitle}/${pdf.filename}`
				const isList = this.isList
				plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
					console.log('文件存在', entry.isFile);
					if (entry.isFile) {
						uni.navigateTo({
							url: '/pages/pdfPreview/index?path=' + encodeURIComponent(`${filePath}`) +
								'&isList=' + isList,
						})
					} else {
						uni.showToast({
							title: '无详情',
							icon: 'none'
						})
					}
				}, function(err) {
					uni.showToast({
						title: '无详情',
						icon: 'none'
					})
				});
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},

			onLoad(item) {
				const file = JSON.parse(item.file)
				this.navbarTitle = file.filename
				this.filekey = file.filekeys;
				this.pdfFiles = file.children
				this.meetId = item.meetId
				this.isList = item.isList
				this.grouping = isdRootPathouping
			},
		}
	}
</script>

<style>
	.pdf-list-page {
		padding: 15rpx;
		background-color: #f6f8fa;
		min-height: 100vh;
	}

	.header {
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 30rpx;
		text-align: center;
	}

	.pdf-grid {
		display: flex;
		flex-wrap: wrap;
		gap: 10rpx
			/* justify-content: space-around; */
	}

	.pdf-card {
		width: 100%;
		box-sizing: border-box;
		background-color: #ffffff;
		border-radius: 4rpx;
		box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.1);
		/* margin: 20rpx; */
		padding: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 20rpx;
		transition: transform 0.2s ease;
	}

	.pdf-card:hover {
		transform: scale(1.03);
	}

	.pdf-icon {
		width: 30rpx;
		height: 30rpx;
		/* background: url('/static/pdf.png'); */
		background-image: url('/static/pdf.png');
		background-size: cover;
		background-repeat: no-repeat;
	}

	.pdf-name {
		width: 100%;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		font-size: 22rpx;
		color: #333;
	}

	.empty {
		position: relative;
		width: 10rem;
		height: 10rem;
		background: url('/static/empty.png') no-repeat;
		background-size: 100% auto;
		object-fit: cover;
		margin: 2rem auto;

		.empty-text {
			white-space: nowrap;
			position: absolute;
			bottom: -0.8rem;
			left: 50%;
			transform: translateX(-50%);
		}
	}


	.bottom_tool {
		position: fixed;
		width: 750rpx;
		background-color: rgba(255, 255, 255, 0.9);
		box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.08);
		left: 0px;
		bottom: 0px;
	}

	.tool_box {
		width: 750rpx;
		height: 50px;
		display: flex;
		align-items: center;
		flex-direction: row;
		justify-content: space-around;
	}
</style>